package com.xxcxcxcx.jobsystem.mixin.job.Blacksmith;


import com.xxcxcxcx.jobsystem.Main;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import static com.xxcxcxcx.jobsystem.common.Job.Blacksmith.Blacksmith.*;

@Mixin(DiggerItem.class)
public abstract class ItemStackSpeedMixin extends Item {
    @Shadow @Final private TagKey<Block> blocks;
    @Shadow @Final protected float speed;

    public ItemStackSpeedMixin(Properties p_41383_) {
        super(p_41383_);
    }

    @Override
    public float getDestroySpeed(ItemStack p_41004_, BlockState p_41005_) {
        if(!p_41005_.is(this.blocks))return 1.0f;
        float num=this.speed;
        CompoundTag compoundTag=p_41004_.getOrCreateTag();
        if(compoundTag.contains(Main.MOD_ID)){
            CompoundTag nbt = compoundTag.getCompound(Main.MOD_ID);
            if(nbt.contains(MakeTool+ToolLevel)){
                num *= num*nbt.getFloat(MakeTool+Speed);
            }
        }else{
            num = num/10;
        }
        return num;
    }
}
